import os
import sys
import GeoIP

path = os.path.abspath(os.path.dirname(__file__))
gi = GeoIP.open(path+'/GeoIPCity.dat', GeoIP.GEOIP_STANDARD)

def ip2region(ip):
        r = gi.record_by_addr(ip)
        if r == None:
                return None
        try:
                return r['region_name']
        except KeyError:
                return None

def ip2city(ip):
        r = gi.record_by_addr(ip)
        if r == None:
                return None
        try:
                return r['city']
        except KeyError:
                return None
